<%-- 
    Document   : EnregistrerPersonne
    Created on : 4 mai 2012, 10:07:30
    Author     : Morgan
--%>

<%@page import="Personne.Personne"%>
<%@page import="Personne.PersonneFacadeLocal"%>
<%@page import="javax.naming.InitialContext"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    String nom = request.getParameter("nom");
    String prenom = request.getParameter("prenom");
    String login = request.getParameter("login");
    String password = request.getParameter("password");
    int age = -1;
    int flagError = 0;
     
    if(nom.isEmpty() || prenom.isEmpty() || login.isEmpty() || password.isEmpty()) flagError= - 1;
        
    try
    {
        age = new Integer(request.getParameter("age"));
    }
    catch(Exception e){
        flagError = -1;
    }
    
    if(flagError == 0)
    {
        Personne personne = new Personne(nom, prenom, login, password, age);
        InitialContext ctx = new InitialContext();
        PersonneFacadeLocal personnefacadeLocal = (PersonneFacadeLocal) ctx.lookup("java:global/TP-Personne-EJB/TP-Personne-EJB-ejb/PersonneFacade!Personne.PersonneFacadeLocal");
        
        personnefacadeLocal.create(personne);
    }
    
%>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <link rel="stylesheet" href="styles.css" type="text/css" />
    </head>
    <body>
        <jsp:include page="menuNavigation.jsp"/>
        
        <div class="content">
            <h1>Insersion de la personne</h1>
            <% if(flagError == 0){%>

            <p>Done</p>

            <%} else{%>

            <p>Informations non valide</p>
            <a href="saisirPersonne.jsp">Retour à la saisie</a>

            <%}%>
        </div>
    </body>
</html>
